/*
 * @Description: file content
 */
/*
 * @Description: ProductService
 */
const ProductModel = require("../../models/ProductModel")

const ProductService = {
  add: async ({ title, productImg, detail, introduction }) => {
    return ProductModel.create({ title, productImg, detail, introduction })
  },
  getList: async (id) => {
    return id ? ProductModel.find({ _id: id }) : ProductModel.find({})
  },
  delOne: async ({ _id }) => {
    return ProductModel.deleteOne({ _id })
  },
  updateOne: async ({ title, productImg, detail, introduction ,_id}) => {
     // 有无更换图片
     if (productImg) {
      return ProductModel.updateOne({ _id }, {
        title, detail, introduction ,productImg
      })
    } else {
      return ProductModel.updateOne({ _id }, {
        title, detail, introduction
      })
    }
  },
}
module.exports = ProductService
